package com.qingfeng.client.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qingfeng.client.VO.PostageQueryVo;
import com.qingfeng.client.VO.PostageVo;
import com.qingfeng.client.bean.Seller;
import com.qingfeng.client.service.PostageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author zhangyuefei
 * @version 1.0
 * @date 2020/4/29 11:14 上午
 */
@Api(tags = "邮费")
@RestController
@RequestMapping("/postpage")
public class PostageApi extends BaseV1Api{

    @Autowired
    private PostageService postageService;

    @ApiOperation("新增邮费模版")
    @PostMapping("/save")
    public Object add(@RequestBody @Valid PostageVo postageVo){
        Seller seller = getUser();
        postageVo.setStoreId(seller.getStoreId());
        postageService.save(postageVo);
        return success("新增成功");
    }

    @ApiOperation("修改邮费模版")
    @PostMapping("/update")
    public Object update(@RequestBody @Valid PostageVo postageVo){
        Seller seller = getUser();
        postageVo.setStoreId(seller.getStoreId());
        postageService.update(postageVo);
        return success("修改成功");
    }

    @ApiOperation("查询邮费模版")
    @PostMapping("/query")
    public Object query(@RequestBody PostageQueryVo postageQueryVo){
        Seller seller = getUser();
        postageQueryVo.getCondition().setStoreId(seller.getStoreId());
        IPage<PostageVo> ipage = postageService.query(postageQueryVo);
        return successPage(ipage);
    }

    @ApiOperation("删除邮费模版")
    @PostMapping("/delete")
    public Object delete(@NotNull(message = "模版id不能为空") @RequestBody List<Integer> ids){
        Seller seller = getUser();
        postageService.delete(ids,seller.getStoreId());
        return success("删除成功");
    }


    @ApiOperation("获取所有正在使用的地址信息")
    @GetMapping("/getUsingAddress")
    public Object getUsingAddress(){
        Seller seller = getUser();
        List list = postageService.getUsingAddress(seller.getStoreId());
        return success(list);
    }

}
